Priority Queue Pattern

This document describes the Priority Queue Pattern example from the guide Cloud Design Patterns (see http://aka.ms/Cloud-Design-Patterns).

 


 

Before you start

 

Ensure that you have installed all of the software prerequisites. For details see the Release Notes.

 

The example demonstrates operational aspects of applications running in Windows Azure. Therefore, you will need to use the diagnostics tools in order to understand how the code sample works. You must ensure that the web and worker roles in the solution are configured to use the diagnostics mechanism. If not, you will not see the trace information generated by the example.

 


 

About the Example

 

This example shows how you can implement priority queues by using Service Bus Topics and Subscriptions. A worker role is responsible for sending messages to a topic. It assigns a priority to each message. The receiving worker roles read messages from subscriptions that have the corresponding priority. In the example, The PriorityQueue.High worker role runs with two instances, whereas the PriorityQueue.Low worker runs only with one. This ensures that high priority messages are read from the queue more quickly than low priority messages.

 


 

Running the Example

 

You can run this example locally in the Visual Studio Windows Azure emulator. You can also run this example by deploying it to a Windows Azure Cloud Service.

 

  • Start Visual Studio using an account that has Administrator privileges ("Run as Administrator").
  • Open the solution you want to explore from the subfolders where you downloaded the examples.
  • Right-click on each role in Solution Explorer, select Properties, and ensure that the role is configured to generate diagnostic information.
  • Provision a Windows Azure Service Bus Namespace
  • Edit the ServiceBus.ConnectionString setting by changing "[SERVICE BUS CONNECTION STRING]" to your own Service Bus endpoint in the following files for every role in the solution:
    • ServiceConfiguration.Cloud.csfg if you will run the example on Windows Azure.
    • ServiceConfiguration.Local.csfg if you will run the example in the Windows Azure Emulator.
      (you can update settings by right-clicking on each of the roles and selecting Properties, or by editing the files directly in the main Visual Studio window.)
  • If you want to run the example in the local Windows Azure emulator:
    • Press F5 in Visual Studio to start the example running.
    • Open the Windows Azure Compute Emulator UI from the icon in the notification area.
    • Select each role in turn and view the diagnostic information generated by Trace statements in the code.
  • If you want to run the example on Windows Azure:
    • Provision a Windows Azure Cloud Service and deploy the application to it from Visual Studio.
    • Open the Server Explorer Window in Visual Studio and expand the Windows Azure entry.
    • Expand Cloud Services and then expand the entry for the solution you deployed.
    • Right-click each role instance and select View Diagnostics Data to see the diagnostic information generated by Trace statements in the code. This is written to the WADLogsTable in the Storage/Development/Tables section.